package com.baize.baizeapp.test.mohu

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Rect
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import android.util.Log
import android.view.PixelCopy
import android.view.View
import android.widget.ImageView
import com.baize.baizeapp.R
import jp.wasabeef.blurry.Blurry

class TranslacentActivity : AppCompatActivity() {

    companion object {
        fun open(context: Context, bitmap: Bitmap) {
            val intent = Intent(context, TranslacentActivity::class.java)
            intent.putExtra("bg", bitmap)
            context.startActivity(intent)
        }
    }

    lateinit var image_bg: ImageView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_translacent)
        image_bg = findViewById<ImageView>(R.id.image_bg)
        image_bg.post {
//            val bitmap = getBitmapFromView(window.decorView,50)
//            image_bg.setImageBitmap(FastBlurUtil.doBlur(bitmap, 20, false))
//
//            getBitmapFromView(window.decorView, this) {
//                image_bg.setImageBitmap(FastBlurUtil.doBlur(it, 20, false))
//            }

//            val bitmap = intent.getParcelableExtra<Bitmap>("bg")
//            image_bg.setImageBitmap(bitmap)

            ScreenShotImageHelper.getScreenBlurBg()?.let { bitmap ->
//                image_bg.setImageBitmap(bitmap)

                Blurry.with(this)
                    .radius(5)    //值越大越模糊
                    .sampling(2)   //对原图像抽样
                    .async()       //异步
                    .from(bitmap)   //对bmp做高斯模糊
                    .into(image_bg) //把结果写入ImageView
            }
        }
    }

}